package com.zheng.cloud.Proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class ProxyTest {

    public static void main(String[] args) {
        /**
         * 静态代理测试
         */
//        Manager manager = new Admin();
//        ProxyAdmin proxyAdmin = new ProxyAdmin(manager);
//        proxyAdmin.doSomething();


        /**
         * 动态代理测试
         */
        Car car = new Car();
        InvocationHandler h = new TimeHandler(car);
        Class<?> cls = car.getClass();
        /**
         *loader 类加载器
         *interfaces 实现接口
         *h InvocationHandler
         */
        Movable m = (Movable) Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), h);
        m.move();
    }
}
